<extend name="Public/base"/>
<block name="content">
  <div class="admin-content">
    <div class="admin-content-body">
      <div class="am-cf am-padding am-padding-bottom-0">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">提币管理</strong>  <small></small></div>
      </div>

      <hr>

      <form class="am-g" action="{:U()}" method="get">
        <select data-am-selected="{btnSize: 'sm'}" name="status">
          <option value="0" <php>if($status == "") echo 'selected'</php>>全部</option>
          <option value="2" <php>if($status == 2) echo 'selected'</php>>待审核</option>
          <option value="1" <php>if($status == 1) echo 'selected'</php>>已完成</option>
          <option value="3" <php>if($status == 3) echo 'selected'</php>>已驳回</option>
        </select>

          <input type="text" class="" name="phone" value="{$phone}"  placeholder="手机号查询">
          <button class="am-btn am-btn-primary" type="submit">搜索</button>
        <!-- <div class="am-u-sm-12 am-u-md-1">
          <div class="am-btn-toolbar">
            <div class="am-btn-group am-btn-group-xs">
              <a href="{:U('user/exportOrder')}" type="button" class="am-btn am-btn-primary"><span class="am-icon-plus"></span>提现未处理</a>
            </div>
          </div>

        </div>
        <div class="am-u-sm-12 am-u-md-1">
          <div class="am-btn-toolbar">
            <div class="am-btn-group am-btn-group-xs">
              <a href="{:U('user/exportOrder1')}" type="button" class="am-btn am-btn-primary"><span class="am-icon-plus"></span>提现已处理</a>
            </div>
          </div>

        </div> -->
      <!--   <div class="am-u-sm-12 am-u-md-2">
          <input type="text" class="am-form-field" name="start_time"  value="{$start_time}" placeholder="开始时间" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',readOnly:true})" readonly/>
        </div>
        <div class="am-u-sm-12 am-u-md-2">
          <input type="text" class="am-form-field" name="end_time"  value="{$end_time}" placeholder="结束时间" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',readOnly:true})" readonly/>
        </div>
        <div class="am-u-sm-12 am-u-md-2">
          <div class="am-input-group am-input-group-sm">
            <input type="text" class="am-form-field" name="username" value="{$username}" placeholder="会员用户名">
          </div>
        </div>
        <div class="am-u-sm-12 am-u-md-2">
          <div class="am-form-group">
            <select data-am-selected="{btnSize: 'sm'}" name="status">
              <option value="2" <php>if($status == 2) echo 'selected'</php>>待审核</option>
              <option value="1" <php>if($status == 1) echo 'selected'</php>>已完成</option>
              <option value="3" <php>if($status == 3) echo 'selected'</php>>已驳回</option>
            </select>
          <!--</div>-->
        <!--</div>-->

        <!-- <div class="am-u-sm-12 am-u-md-2">
          <div class="am-input-group am-input-group-sm">

            <span class="am-input-group-btn">
            <button class="am-btn am-btn-primary" type="submit">搜索</button>
          </span>
          </div>
        </div> -->

      </form>
      <button class="am-btn am-btn-primary yijian">一键通过</button>
      <div class="am-g">
        <div class="am-u-sm-12">
          <div class="am-form">
            <table class="am-table am-table-striped am-table-hover table-main">
              <thead>
              <tr>
                <th><input type="checkbox" id="all"></th>
                <th class="table-title">序号</th>
                  <th class="table-set">操作</th>
                <th class="table-title">用户ID</th>
                <th class="table-title">手机号</th>
                <th class="table-type">币种名称</th>
                <th class="table-type">提币地址</th>
                <th class="table-type">充币数量</th>
                <th class="table-type">交易hash</th>
                <!-- <th class="table-type">到账金额</th> -->
                <th class="table-type">状态</th>
                <th class="table-type">手续费</th>
<!--                 <th class="table-author am-hide-sm-only">银行卡号</th>
                <th class="table-date am-hide-sm-only">开户银行</th>
                <th class="table-date am-hide-sm-only">银行支行</th>
                <th class="table-date am-hide-sm-only">持卡人</th>
                <th class="table-date am-hide-sm-only">微信</th>
                <th class="table-date am-hide-sm-only">支付宝</th> -->
                <th class="table-date am-hide-sm-only">提交时间</th>
                <th class="table-date am-hide-sm-only">确认时间</th>
                <th class="table-date am-hide-sm-only">平台钱包</th>

              </tr>
              </thead>
              <tbody>
              <empty name="data">
                <tr>
                  <td>暂无数据</td>
                </tr>
              </empty>
              <php>
                $tixian = C('WITHDRAW_STATUS');
                $type = C('account_type');
              </php>
              <volist name="data" id="vo">
                <tr>
                  <td>
                    <if condition="$vo.status eq 2">
                      <input type="checkbox" class="every" id="{$vo.id}" value="{$vo.id}" coin="{$vo.coinname}" n="{$vo.address}" x="{$vo.id}" m="{$vo.amount}">
                    </if>
                  </td>
                  <td>{$vo['id']}</td>
                    <td>
                        <if condition="$vo['status'] eq 2">

                            <!-- 操作BTC -->
                            <if condition="$vo['status'] eq 2 AND $vo['coinname'] eq btc">

                                <div class="am-dropdown" data-am-dropdown="">

                                    <button class="am-btn am-btn-default am-btn-xs am-dropdown-toggle" data-am-dropdown-toggle=""><span class="am-icon-cog"></span> <span class="am-icon-caret-down"></span></button>

                                    <ul class="am-dropdown-content">

                                        <li class="tbtc" id="{$vo['id']}"><a href="#">待审核</a></li>

                                        <li><a href="{:U('doReject',array('id'=>$vo['id'],'status'=>3,'userid'=>$vo['userid'],'amount'=>$vo['amount'],'coinname'=>$vo['coinname']))}">待驳回</a></li>

                                    </ul>

                                </div>

                            </if>

                            <!-- 操作ETH -->
                            <if condition="$vo['status'] eq 2 AND $vo['coinname'] eq eth">

                                <div class="am-dropdown" data-am-dropdown="">

                                    <button class="am-btn am-btn-default am-btn-xs am-dropdown-toggle" data-am-dropdown-toggle=""><span class="am-icon-cog"></span> <span class="am-icon-caret-down"></span></button>

                                    <ul class="am-dropdown-content">

                                        <li class="teth" id="{$vo['id']}" m="{$vo.amount}" n="{$vo.address}" x="{$vo.id}"><a href="#">待审核</a></li>

                                        <li><a href="{:U('doReject',array('id'=>$vo['id'],'status'=>3,'userid'=>$vo['userid'],'amount'=>$vo['amount'],'coinname'=>$vo['coinname']))}">待驳回</a></li>

                                    </ul>

                                </div>

                            </if>

                            <!-- 操作USDT -->

                            <if condition="$vo['status'] eq 2 AND $vo['coinname'] eq usdt">

                                <div class="am-dropdown" data-am-dropdown="">

                                    <button class="am-btn am-btn-default am-btn-xs am-dropdown-toggle" data-am-dropdown-toggle=""><span class="am-icon-cog"></span> <span class="am-icon-caret-down"></span></button>

                                    <ul class="am-dropdown-content">

                                        <li class="tusdt" id="{$vo['id']}" m="{$vo.amount}" n="{$vo.address}" x="{$vo.id}"><a href="#">待审核</a></li>

                                        <li><a href="{:U('doReject',array('id'=>$vo['id'],'status'=>3,'userid'=>$vo['userid'],'amount'=>$vo['amount'],'coinname'=>$vo['coinname']))}">待驳回</a></li>

                                    </ul>

                                </div>

                            </if>


                            <!-- 操作WFX -->

                            <if condition="$vo['status'] eq 2 AND $vo['coinname'] eq wfx">

                                <div class="am-dropdown" data-am-dropdown="">

                                    <button class="am-btn am-btn-default am-btn-xs am-dropdown-toggle" data-am-dropdown-toggle=""><span class="am-icon-cog"></span> <span class="am-icon-caret-down"></span></button>

                                    <ul class="am-dropdown-content">

                                        <li class="twfx" id="{$vo['id']}" m="{$vo.amount}" n="{$vo.address}" x="{$vo.id}"><a href="#">待审核</a></li>

                                        <li><a href="{:U('doReject',array('id'=>$vo['id'],'status'=>3,'userid'=>$vo['userid'],'amount'=>$vo['amount'],'coinname'=>$vo['coinname']))}">待驳回</a></li>

                                    </ul>

                                </div>

                            </if>


                            <else/>
                            ---
                        </if>
                    </td>
                  <td>{$vo['userid']}</td>
                  <td><a href="#">{$vo['phone']}</a></td>
                  <td><a href="#">{$vo['coinname']|strtoupper}</a></td>
                  <!--<td><a href="#">{$vo['address']}</a></td>-->

                  <if condition="$vo['coinname'] neq btc">
                    <td><a href="https://etherscan.io/address/{$vo['address']}" target="_blank">
                      {$vo['address']}</a></td>
                    <else/>
                    <td><a href="https://btc.com/{$vo['address']}" target="_blank">
                      {$vo['address']}</a></td>
                  </if>
                  <td>{$vo['amount']}</td>

                  <!-- <td>{$vo['sxf']}</td> -->
                  <!-- <td>{$vo['amount'] - $vo['sxf']}</td> -->
                  <if condition="$vo['coinname'] neq btc">
                    <td><a href="https://etherscan.io/tx/{$vo['hash']}" target="_blank">
                    {$vo['hash']}</a></td>
                  <else/>
                    <td><a href="https://btc.com/{$vo['hash']}" target="_blank">
                    {$vo['hash']}</a></td>
                  </if>
                  <td>
                    {$tixian[$vo['status']]}
                  </td>
                  <td>{$vo['fee']}</td>
                  <!-- <td class="am-hide-sm-only">
                      {$vo['bank_num']}
                  </td>
                  <td class="am-hide-sm-only">
                    {$vo['bank_name']}
                  </td> -->

                  <!-- <td class="am-hide-sm-only">
                    {$vo['bank_tree']}
                  </td>
                  <td class="am-hide-sm-only">
                    {$vo['bank_user']}
                  </td>
                  <td class="am-hide-sm-only">
                    {$vo['weixin']}
                  </td>
                  <td class="am-hide-sm-only">
                    {$vo['zfb']}
                  </td> -->
                  <td class="am-hide-sm-only">{$vo['addtime']|date="Y-m-d H:i:s",###}</td>
                  <if condition="$vo['endtime'] eq 0">
                        <td class="am-hide-sm-only">---</td>
                  <else/>

                        <td class="am-hide-sm-only">{$vo['endtime']|date="Y-m-d H:i:s",###}</td>

                  </if>

                  <td>

                  <if condition="$vo['coinname'] eq btc">

                    {$balance}

                  <elseif condition="$vo['coinname'] eq eth" />

                    <span class="eth"></span>

                  <elseif condition="$vo['coinname'] eq usdt" />

                    <span class="usdt"></span>

                  <elseif condition="$vo['coinname'] eq wfx" />

                    <span class="wfx"></span>

                  </if>

                  </td>  


                </tr>
              </volist>
              </tbody>
            </table>
            <div class="am-cf">
              共 {$count} 条记录
              <div class="am-fr">
                <ul class="am-pagination">
                  {$page}

                </ul>
              </div>
            </div>
            <hr/>
        </div>

        </div>

      </div>
    </div>

    <footer class="admin-content-footer">
      <hr>
      <p class="am-padding-left">© 2014 AllMobilize, Inc. Licensed under MIT license.</p>
    </footer>

  </div>

  <!-- 引入js -->

  <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
  <script type="text/javascript" src="/Public/Home/js/web3.1.js"></script>
  <!--<script src="__PUBLIC__/Admin/js/withdrawcoin.js"></script>-->

  <!-- 查询平台钱包和转账 -->

  <script type="text/javascript">

      $('#all').click(function () {
          // console.log(this.checked);
          // $(".every").attr('checked',this.checked);
         $(".every").prop('checked',this.checked);
      })

      $('.every').click(function () {
          $flag=true;
          $(".every").each(function () {
              if(!this.checked){
                  $flag=false;
              }
          })
          $("#all").prop('checked',$flag);
      })

      $(".yijian").click(function () {
          // alert(123);return false;
          $flag=true;
          if(confirm("确定执行此操作吗")){
              $arr=[];
              $(".every").each(function () {
                  if(this.checked){
                      $arr.push($(this).val());
                      // alert($(this).attr('n'));
                      if($(this).attr('coin')=='wfx'){
                          twfx($(this));
                      }
                      if($(this).attr('coin')=='btc'){
                          // twfx();
                          tbtc($(this));
                      }
                      if($(this).attr('coin')=='eth'){
                          // twfx();
                          teth($(this));
                      }
                      if($(this).attr('coin')=='usdt'){
                          // twfx();
                          tusdt($(this));
                      }
                  }
              });
              if($flag==true){
                  alert('批量审核已完成');
                  window.location.reload();
              }else {
                  alert('部分会员审核未通过，请手动驳回');
                  window.location.reload();
              }
              // window.location.reload();
              // alert($arr+"||"+$flag);
              // $.ajax({
              //     type:"post",
              //     dataType:"json",
              //     url:"{:U('yijian_sure')}",
              //     data:{
              //         arr:$arr,
              //     },
              //     success:function (data) {
              //         if(data.code>0){
              //             alert(data.message);
              //             window.location.reload();
              //         }else {
              //             alert(data.message);
              //         }
              //     }
              // })
          }

      })




    if (typeof web3 !== 'undefined') {
        web3 = new Web3(web3.currentProvider);
    } 
    else {        
        web3 = new Web3('https://mainnet.infura.io/JLEYzEEavNnSni91CvPF');
    }

    var address = "0xF4aC5D9be4aEa89b4e607752bcBD31D0A7dFfE16";

    //查询eth余额
    var eth = '';
    web3.eth.getBalance(address, function(err, resp){
        if(!err){
            eth = web3.utils.fromWei(resp, 'ether');
            $(".eth").append(eth);
        }else{
            console.log(err);
        }
    });


    //查询usdt余额 
    var usdtContractAddress = '0xdac17f958d2ee523a2206206994597c13d831ec7';
    var usdtContract = new web3.eth.Contract([{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_upgradedAddress","type":"address"}],"name":"deprecate","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"deprecated","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_evilUser","type":"address"}],"name":"addBlackList","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"upgradedAddress","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"balances","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"maximumFee","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"_totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"unpause","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_maker","type":"address"}],"name":"getBlackListStatus","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"address"}],"name":"allowed","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"paused","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"who","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"pause","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getOwner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"newBasisPoints","type":"uint256"},{"name":"newMaxFee","type":"uint256"}],"name":"setParams","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"amount","type":"uint256"}],"name":"issue","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"amount","type":"uint256"}],"name":"redeem","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"remaining","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"basisPointsRate","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"isBlackListed","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_clearedUser","type":"address"}],"name":"removeBlackList","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"MAX_UINT","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_blackListedUser","type":"address"}],"name":"destroyBlackFunds","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[{"name":"_initialSupply","type":"uint256"},{"name":"_name","type":"string"},{"name":"_symbol","type":"string"},{"name":"_decimals","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"amount","type":"uint256"}],"name":"Issue","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"amount","type":"uint256"}],"name":"Redeem","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"newAddress","type":"address"}],"name":"Deprecate","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"feeBasisPoints","type":"uint256"},{"indexed":false,"name":"maxFee","type":"uint256"}],"name":"Params","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"_blackListedUser","type":"address"},{"indexed":false,"name":"_balance","type":"uint256"}],"name":"DestroyedBlackFunds","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"_user","type":"address"}],"name":"AddedBlackList","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"_user","type":"address"}],"name":"RemovedBlackList","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[],"name":"Pause","type":"event"},{"anonymous":false,"inputs":[],"name":"Unpause","type":"event"}], usdtContractAddress, {
    from : '0xF4aC5D9be4aEa89b4e607752bcBD31D0A7dFfE16'
    });
    
    var usdt = '';

    usdtContract.methods.balanceOf(address).call(function(err, tkns){
        if (!err) {
          usdt = web3.utils.fromWei(tkns, 'mwei');
          $(".usdt").append(usdt);
        }else{
            console.log(err)
        }
        
    })


    //查询wfx余额
    var wfxContractAddress = '0xba1ed22c69ad00739ee2b4abd70e270be9e87ee2';
    var wfxContract = new web3.eth.Contract([{"constant":false,"inputs":[{"name":"addr","type":"address"},{"name":"state","type":"bool"}],"name":"setTransferAgent","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"mintingFinished","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"addr","type":"address"}],"name":"setReleaseAgent","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"receiver","type":"address"},{"name":"amount","type":"uint256"}],"name":"mint","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"burnAmount","type":"uint256"}],"name":"burn","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"mintAgents","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"addr","type":"address"},{"name":"state","type":"bool"}],"name":"setMintAgent","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"value","type":"uint256"}],"name":"upgrade","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_name","type":"string"},{"name":"_symbol","type":"string"}],"name":"setTokenInformation","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"upgradeAgent","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"releaseTokenTransfer","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"upgradeMaster","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_subtractedValue","type":"uint256"}],"name":"decreaseApproval","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"addr","type":"address"},{"name":"state","type":"bool"}],"name":"setLockAddress","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"fromWhom","type":"address"}],"name":"transferToOwner","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getUpgradeState","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"transferAgents","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"released","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"canUpgrade","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"lockAddresses","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"totalUpgraded","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"releaseAgent","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_addedValue","type":"uint256"}],"name":"increaseApproval","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"agent","type":"address"}],"name":"setUpgradeAgent","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"isToken","outputs":[{"name":"weAre","type":"bool"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"BURN_ADDRESS","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"master","type":"address"}],"name":"setUpgradeMaster","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[{"name":"_name","type":"string"},{"name":"_symbol","type":"string"},{"name":"_initialSupply","type":"uint256"},{"name":"_decimals","type":"uint256"},{"name":"_mintable","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"fromWhom","type":"address"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"OwnerReclaim","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"newName","type":"string"},{"indexed":false,"name":"newSymbol","type":"string"}],"name":"UpdatedTokenInformation","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_from","type":"address"},{"indexed":true,"name":"_to","type":"address"},{"indexed":false,"name":"_value","type":"uint256"}],"name":"Upgrade","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"agent","type":"address"}],"name":"UpgradeAgentSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"addr","type":"address"},{"indexed":false,"name":"state","type":"bool"}],"name":"MintingAgentChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"receiver","type":"address"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"Minted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"burner","type":"address"},{"indexed":false,"name":"burnedAmount","type":"uint256"}],"name":"Burned","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"}], wfxContractAddress, {
    from : '0xF4aC5D9be4aEa89b4e607752bcBD31D0A7dFfE16'
    });
    
    var wfx = '';    
    wfxContract.methods.balanceOf(address).call(function(err, tkns){
        if (!err) {
          wfx = web3.utils.fromWei(tkns, 'ether');
          $(".wfx").append(wfx);
        }else{
            console.log(err)
        }
        
    })

    //btc转账
    $('.tbtc').click(function(event) {

        // alert('暂未开放！');
        // return false;

        if(confirm("确认操作？")){

            var id = $(this).attr('id');

            $.ajax({
                type: 'POST',
                url: '{:U("doWithdrawBTC")}',
                data: {  
                    'id':id
                },

                dataType: 'json',

                success: function(data){                                     
                    if (data.code == 0) {
                        alert(data.msg);
                        window.location.reload();
                        return;
                    } else {
                        alert(data.msg);
                        window.location.reload();
                        // window.location ="{:U('withdrawCoin')}";
                    }

                }
            });

        }
        else
        {
            return;
        }
    });


    //eth转账
    $('.teth').click(function(){

        // alert('暂未开放！');
        // return false;

        if(confirm("确认操作？")){

        var from = '0xF4aC5D9be4aEa89b4e607752bcBD31D0A7dFfE16';
        var amount = parseFloat($(this).attr("m"));
        var number = parseFloat($(this).attr("m"));
        var to = $(this).attr("n");
        var id = $(this).attr('x');

        if(!web3.utils.isAddress(to)){
            alert('ETH钱包地址不正确');
            return false;
        }
     
        web3.eth.getBalance(from, function(err, resp){
            if(!err){
                
                balance = web3.utils.fromWei(resp, 'ether');
                console.log(balance);           
                    web3.eth.getGasPrice(function(err, res){
                        if(!err)
                        {
                            price = web3.utils.fromWei(res, 'ether'); 
                            //console.log(price);
                            limit = 26000;
                            fee = parseFloat(price) * limit;
                            //console.log(fee);  
                            //console.log(number);
                            num = parseFloat(fee) + parseFloat(number); 
                            //console.log(fee);
                            //console.log(number);
                            //console.log(num);                           
                            if(parseFloat(num) > parseFloat(balance))
                            {
                                alert('平台钱包ETH余额不足');
                                return false;
                            }
                        }
                    });

                }else{
                    console.log(err);
            }
        });  

        web3.eth.getTransactionCount(from, function(err, count){
            if(!err){

                var tcount = count;
                amount = web3.utils.toWei(amount.toString());
                web3.eth.getGasPrice().then(function(gasPrice){
                    var rawTransaction = {
                          "from": from,
                          "nonce": "0x" + tcount.toString(16),
                          "gasPrice": web3.utils.toHex(gasPrice),
                          "gasLimit": web3.utils.toHex(26000),
                          "to": to,
                          "value": amount,
                          "data": ''
                        };

                    var privKey = '0x54C9FC6CF41F649863E6AFAC511E418D7A70E814814598FE5C6634326DCEC791';
                  
                    web3.eth.accounts.signTransaction(rawTransaction, privKey, function(err,signed){
                        if(err){
                            console.log(err);
                            return ;
                        }
                        web3.eth.sendSignedTransaction(signed.rawTransaction, function(err, result){
                            if(!err){
                                console.log(result);
                                //传送数据
                                $.ajax({
                                    type: 'POST',
                                    url: '{:U("doWithdrawETH")}',
                                    data: {                                      
                                        'txhash': result,
                                        'id' : id
                                    },
                                    dataType: 'json',

                                    success: function(data){                                     
                                        if (data.code == 0) {
                                            alert(data.msg);
                                            window.location.reload();
                                            // window.location ="{:U('withdrawCoin')}";
                                        } else {
                                            alert(data.msg);
                                            return;
                                        }

                                    }
                                });
                            }else{
                                console.log(err);
                            }
                        })
                    })

                })  

            }else{
                console.log(error);
            }
        });

    }
    else
    {
        return;
    }

    });

    
    //usdt转账
    $('.tusdt').click(function(){

        // alert('暂未开放！');
        // return false;

        if(confirm("确认操作？")){

        var from = '0xF4aC5D9be4aEa89b4e607752bcBD31D0A7dFfE16';
        var amount = parseFloat($(this).attr("m"));
        var to = $(this).attr("n");
        var id = $(this).attr('x');

        //验证数量
        if(!web3.utils.isAddress(to)){
            alert('钱包地址不正确');
            return false;
        }

        web3.eth.getTransactionCount(from, function(err, count){

            if(!err){
                var tcount = count;
                usdtContract.methods.balanceOf(from).call( function(err, tkns){
                    if (!err) {
                       var balance = web3.utils.fromWei(tkns, 'mwei');
                       console.log(balance);
                       var b = new web3.utils.BN(balance)                

                       if(b.toNumber() < amount){
                            alert('平台钱包USDT余额不足');
                            return false;
                       }

                       amount = web3.utils.toWei(amount.toString(), 'mwei');    
                       
                       web3.eth.getGasPrice().then(function(gasPrice){

                        var rawTransaction = {
                              "from": from,
                              "nonce": "0x" + tcount.toString(16),
                              "gasPrice": web3.utils.toHex(gasPrice),
                              "gasLimit": web3.utils.toHex(60000),
                              "to": usdtContractAddress,
                              "value": "0x0",
                              "data": usdtContract.methods.transfer(to, amount).encodeABI()
                            };

                            var privKey = '0x54C9FC6CF41F649863E6AFAC511E418D7A70E814814598FE5C6634326DCEC791';
                          
                            web3.eth.accounts.signTransaction(rawTransaction, privKey, function(err,signed){

                            if(err){
                                console.log(err);
                                return ;
                            }

                            web3.eth.sendSignedTransaction(signed.rawTransaction, function(err, result){
                                if(!err){
                                    //传送数据
                                    $.ajax({
                                        type: 'POST',
                                        url: '{:U("doWithdrawETH")}',
                                        data: {                                      
                                            'txhash': result,
                                            'id' : id
                                        },
                                        dataType: 'json',

                                        success: function(data){                                           

                                            if (data.code == 0) {
                                                alert(data.msg);
                                                window.location.reload();
                                                // window.location ="{:U('withdrawCoin')}";
                                            } else {
                                                alert(data.msg);
                                                return;
                                            }

                                        }
                                    });
                                }else{
                                    console.log(err);
                                }
                            })
                        })

                    }) 

                    }else{
                        console.log(err)
                    }
                    
                })
            }else{
                console.log(error);
            }
            
        });
    }
    else
    {
        return;
    }

    });


     //wfx转账
    $('.twfx').click(function(){

        //alert('暂未开放！');
        //return false;
        
        if(confirm("确认操作？")){
    
        var from = '0xF4aC5D9be4aEa89b4e607752bcBD31D0A7dFfE16';
        var amount = parseFloat($(this).attr("m"));
   
        var to = $(this).attr("n");
        var id = $(this).attr('x');

        //验证数量
        if(!web3.utils.isAddress(to)){
            alert('钱包地址不正确');
            return false;
        }

        web3.eth.getTransactionCount(from, function(err, count){

            if(!err){
                var tcount = count;
                wfxContract.methods.balanceOf(from).call( function(err, tkns){
                    if (!err) {
                       var balance = web3.utils.fromWei(tkns, 'ether');
                       console.log(balance);
                       var b = new web3.utils.BN(balance)    

                       if(b.toNumber() < amount){
                            alert('平台钱包WFX余额不足');
                            return false;
                       }

                       amount = web3.utils.toWei(amount.toString());    
                       
                       web3.eth.getGasPrice().then(function(gasPrice){

                        var rawTransaction = {
                              "from": from,
                              "nonce": "0x" + tcount.toString(16),
                              "gasPrice": web3.utils.toHex(gasPrice),
                              "gasLimit": web3.utils.toHex(60000),
                              "to": wfxContractAddress,
                              "value": "0x0",
                              "data": wfxContract.methods.transfer(to, amount).encodeABI()
                            };

                            var privKey = '0x54C9FC6CF41F649863E6AFAC511E418D7A70E814814598FE5C6634326DCEC791';
                          
                            web3.eth.accounts.signTransaction(rawTransaction, privKey, function(err,signed){

                            if(err){
                                console.log(err);
                                return ;
                            }

                            web3.eth.sendSignedTransaction(signed.rawTransaction, function(err, result){
                                if(!err){
                                    //传送数据
                                    $.ajax({
                                        type: 'POST',
                                        url: '{:U("doWithdrawETH")}',
                                        data: {                                      
                                            'txhash': result,
                                            'id' : id
                                        },
                                        dataType: 'json',

                                        success: function(data){                                        
                                            //提币失败
                                            if (data.code == 0) {
                                                alert(data.msg);
                                                window.location.reload();
                                                // window.location ="{:U('withdrawCoin')}";
                                            } else {
                                                alert(data.msg);
                                              window.location.reload();
                                                return;
                                            }

                                        }
                                    });
                                }else{
                                    console.log(err);
                                }
                            })
                        })

                    })  

                    }else{
                        console.log(err)
                    }
                    
                })
            }else{
                console.log(error);
            }
            
        });
    }
    else
    {
        return;
    }

    });
//定时执行
setTimeout(function(){
    // console.log(data.msg);return false;
    //传送数据
    $.ajax({
        type: 'POST',
        url: '{:U("Public/autoWithdrawETH")}',
        data: {
            // 'txhash': 1,
            // 'id' : 2
        },
        dataType: 'json',

        success: function(data){
            //提币失败
            if (data.code == 0) {
                if(data.msg.coinname=="btc"){
                    $.ajax({
                        type: 'POST',
                        url: '{:U("doWithdrawBTC")}',
                        data: {
                            'id':data.msg.id
                        },
                        dataType: 'json',
                        success: function(data){
                            if (data.code == 0) {
                                console.log(data.msg);
                                // window.location.reload();
                                return;
                            } else {
                                 console.log(data.msg);
                                // window.location.reload();
                                // window.location ="{:U('withdrawCoin')}";
                            }

                        }
                    });
                }else{
                    // console.log(data.msg);
                    // alert(data.msg);
                    // window.location.reload();
                    // window.location ="{:U('withdrawCoin')}";
                    var from =data.msg.from;
                    var amount =data.msg.amount;//提币金额
                    var to = data.msg.address;//提币地址
                    var id = data.msg.id;//id
                    //验证数量

                    if(!web3.utils.isAddress(to)){
                        console.log('钱包地址不正确');
                        return false;
                    }
                    console.log(data.msg.id);
                    web3.eth.getTransactionCount(from, function(err, count){

                        if(!err){
                            var tcount = count;
                            wfxContract.methods.balanceOf(from).call( function(err, tkns){
                                if (!err) {
                                    var balance = web3.utils.fromWei(tkns, 'ether');
                                    console.log(balance);
                                    var b = new web3.utils.BN(balance)

                                    if(b.toNumber() < amount){
                                        console.log('平台钱包WFX余额不足');
                                        return false;
                                    }

                                    amount = web3.utils.toWei(amount.toString());

                                    web3.eth.getGasPrice().then(function(gasPrice){

                                        var rawTransaction = {
                                            "from": from,
                                            "nonce": "0x" + tcount.toString(16),
                                            "gasPrice": web3.utils.toHex(gasPrice),
                                            "gasLimit": web3.utils.toHex(60000),
                                            "to": wfxContractAddress,
                                            "value": "0x0",
                                            "data": wfxContract.methods.transfer(to, amount).encodeABI()
                                        };

                                        // var privKey = '0x54C9FC6CF41F649863E6AFAC511E418D7A70E814814598FE5C6634326DCEC791';
                                        // var privKey = privKey;
                                        var privKey = data.msg.key;


                                        web3.eth.accounts.signTransaction(rawTransaction, privKey, function(err,signed){

                                            if(err){
                                                console.log(err);
                                                return ;
                                            }
                                            web3.eth.sendSignedTransaction(signed.rawTransaction, function(err, result){
                                                if(!err){

                                                    //传送数据
                                                    $.ajax({
                                                        type: 'POST',
                                                        url: '{:U("doWithdrawETH")}',
                                                        data: {
                                                            'txhash': result,
                                                            'id' : id
                                                        },
                                                        dataType: 'json',

                                                        success: function(data){
                                                            //提币失败
                                                            if (data.code == 0) {
                                                                console.log(data.msg);
                                                                // alert(data.msg);
                                                                // window.location.reload();
                                                                // window.location ="{:U('withdrawCoin')}";
                                                            } else {
                                                                console.log(data.msg);
                                                                // alert(data.msg);
                                                                // window.location.reload();
                                                                // return;
                                                            }

                                                        }
                                                    });
                                                }else{
                                                    console.log(err);
                                                }
                                            })
                                        })

                                    })

                                }else{
                                    console.log(err)
                                }

                            })
                        }else{
                            console.log(error);
                        }

                    });
                }

            } else {
                console.log(data.msg);
                // alert(data.msg);
                // window.location.reload();
                // return;
            }

        }
    });
},60000);
      //wfx转账
      function twfx(obj){
          var from = '0xF4aC5D9be4aEa89b4e607752bcBD31D0A7dFfE16';
          var amount = parseFloat(obj.attr("m"));
          var to = obj.attr("n");
          var id = obj.attr('x');
          // alert(to);
          //验证数量

          if(!web3.utils.isAddress(to)){
              alert('钱包地址不正确');
              $flag=false;
              layer.msg(id+"会员钱包地址不正确");
              return true;
          }
          // console.log(web3);
          web3.eth.getTransactionCount(from, function(err, count){

              alert(from);return false;
              if(!err){
                  var tcount = count;
                  wfxContract.methods.balanceOf(from).call( function(err, tkns){
                      if (!err) {
                          var balance = web3.utils.fromWei(tkns, 'ether');
                          console.log(balance);
                          var b = new web3.utils.BN(balance)

                          if(b.toNumber() < amount){
                              alert('平台钱包WFX余额不足');
                              $flag=false;
                              layer.msg(id+"平台钱包WFX余额不足");
                              return true;
                          }

                          // alert('wfx');
                          // return true;
                          amount = web3.utils.toWei(amount.toString());

                          web3.eth.getGasPrice().then(function(gasPrice){

                              var rawTransaction = {
                                  "from": from,
                                  "nonce": "0x" + tcount.toString(16),
                                  "gasPrice": web3.utils.toHex(gasPrice),
                                  "gasLimit": web3.utils.toHex(60000),
                                  "to": wfxContractAddress,
                                  "value": "0x0",
                                  "data": wfxContract.methods.transfer(to, amount).encodeABI()
                              };

                              var privKey = '0x54C9FC6CF41F649863E6AFAC511E418D7A70E814814598FE5C6634326DCEC791';

                              web3.eth.accounts.signTransaction(rawTransaction, privKey, function(err,signed){

                                  if(err){
                                      $flag=false;
                                      // console.log(err);
                                      layer.msg(id+'会员审核不通过');
                                      return true;
                                  }

                                  web3.eth.sendSignedTransaction(signed.rawTransaction, function(err, result){
                                      if(!err){
                                          // alert('没出错');
                                          //传送数据
                                          $.ajax({
                                              type: 'POST',
                                              url: '{:U("doWithdrawETH")}',
                                              data: {
                                                  'txhash': result,
                                                  'id' : id
                                              },
                                              dataType: 'json',

                                              success: function(data){

                                                  if (data.code == 0) {
                                                      // alert(data.msg);
                                                      $flag=false;
                                                      // window.location ="{:U('withdrawCoin')}";
                                                      layer.msg(id+'会员审核不通过');
                                                      return true;
                                                  } else {
                                                      console.log(data.msg);
                                                      // window.location.reload();
                                                     alert(data.msg);
                                                      // return;
                                                  }

                                              }
                                          });
                                      }else{
                                          $flag=false;
                                          layer.msg(id+'会员审核不通过');
                                          return true;
                                          // console.log(err);
                                      }
                                  })
                              })

                          })

                      }else{
                          $flag=false;
                          layer.msg(id+'会员审核不通过');
                          return true;
                          // console.log(err);
                      }

                  })
              }else{
                  $flag=false;
                  layer.msg(id+'会员审核不通过');
                  return true;
                  // console.log(error);
              }

          });
      }


      //btc转账
      function tbtc(obj){
          // alert('btc');
          // return true;
          var id = obj.attr('id');

          $.ajax({
              type: 'POST',
              url: '{:U("doWithdrawBTC")}',
              data: {
                  'id':id
              },

              dataType: 'json',

              success: function(data){
                  if (data.code != 2) {
                      $flag=false;
                      layer.msg(id+'会员审核不通过');
                  } else {
                    window.location.reload();
                  }

              }
          });

      }




      //eth转账
      function teth(obj){
          var from = '0xF4aC5D9be4aEa89b4e607752bcBD31D0A7dFfE16';
          var amount = parseFloat(obj.attr("m"));
          var number = parseFloat(obj.attr("m"));
          var to = obj.attr("n");
          var id = obj.attr('x');

          if(!web3.utils.isAddress(to)){
              // alert('ETH钱包地址不正确');
              $flag=false;
              layer.msg(id+'钱包地址不正确');
              return true;
          }

          web3.eth.getBalance(from, function(err, resp){
              if(!err){

                  balance = web3.utils.fromWei(resp, 'ether');
                  console.log(balance);
                  web3.eth.getGasPrice(function(err, res){
                      if(!err)
                      {
                          price = web3.utils.fromWei(res, 'ether');
                          //console.log(price);
                          limit = 26000;
                          fee = parseFloat(price) * limit;
                          //console.log(fee);
                          //console.log(number);
                          num = parseFloat(fee) + parseFloat(number);
                          //console.log(fee);
                          //console.log(number);
                          //console.log(num);
                          if(parseFloat(num) > parseFloat(balance))
                          {
                              // alert('平台钱包ETH余额不足');
                              $flag=false;
                              layer.msg(id+'会员平台钱包ETH余额不足');
                              return true;
                          }
                      }
                  });

              }else{
                  $flag=false;
                  // console.log(err);
                  layer.msg(id+'会员审核不通过');
                  return true;
              }
          });

          // alert('eth');
          // return true;
          web3.eth.getTransactionCount(from, function(err, count){
              if(!err){

                  var tcount = count;
                  amount = web3.utils.toWei(amount.toString());
                  web3.eth.getGasPrice().then(function(gasPrice){
                      var rawTransaction = {
                          "from": from,
                          "nonce": "0x" + tcount.toString(16),
                          "gasPrice": web3.utils.toHex(gasPrice),
                          "gasLimit": web3.utils.toHex(26000),
                          "to": to,
                          "value": amount,
                          "data": ''
                      };

                      var privKey = '0x54C9FC6CF41F649863E6AFAC511E418D7A70E814814598FE5C6634326DCEC791';

                      web3.eth.accounts.signTransaction(rawTransaction, privKey, function(err,signed){
                          if(err){
                              // console.log(err);
                              $flag=false;
                              layer.msg(id+'会员审核不通过');
                              return true;
                          }
                          web3.eth.sendSignedTransaction(signed.rawTransaction, function(err, result){
                              if(!err){
                                  console.log(result);
                                  //传送数据
                                  $.ajax({
                                      type: 'POST',
                                      url: '{:U("doWithdrawETH")}',
                                      data: {
                                          'txhash': result,
                                          'id' : id
                                      },
                                      dataType: 'json',

                                      success: function(data){
                                          if (data.code == 0) {
                                              $flag=false;
                                              layer.msg(id+'会员审核不通过');
                                              return true;
                                          } else {
                                            window.location.reload();
                                          }

                                      }
                                  });
                              }else{
                                  $flag=false;
                                  // console.log(err);
                                  layer.msg(id+'会员审核不通过');
                                  return true;
                              }
                          })
                      })

                  })

              }else{
                  $flag=false;
                  layer.msg(id+'会员审核不通过');
                  return true;
                  // console.log(error);
              }
          });
      }

      //usdt转账
      function tusdt(obj){
          var from = '0xF4aC5D9be4aEa89b4e607752bcBD31D0A7dFfE16';
          var amount = parseFloat(obj.attr("m"));
          var to = obj.attr("n");
          var id = obj.attr('x');

          //验证数量
          if(!web3.utils.isAddress(to)){
              // alert('钱包地址不正确');
              $flag=false;
              layer.msg(id+'会员钱包地址不正确');
              return true;
          }

          web3.eth.getTransactionCount(from, function(err, count){

              if(!err){
                  var tcount = count;
                  usdtContract.methods.balanceOf(from).call( function(err, tkns){
                      if (!err) {
                          var balance = web3.utils.fromWei(tkns, 'mwei');
                          console.log(balance);
                          var b = new web3.utils.BN(balance)

                          if(b.toNumber() < amount){
                              // alert('平台钱包USDT余额不足');
                              $flag=false;
                              layer.msg(id+'会员平台钱包USDT余额不足');
                              return true;
                          }


                          // alert('usdt');
                          // return true;
                          amount = web3.utils.toWei(amount.toString(), 'mwei');

                          web3.eth.getGasPrice().then(function(gasPrice){

                              var rawTransaction = {
                                  "from": from,
                                  "nonce": "0x" + tcount.toString(16),
                                  "gasPrice": web3.utils.toHex(gasPrice),
                                  "gasLimit": web3.utils.toHex(60000),
                                  "to": usdtContractAddress,
                                  "value": "0x0",
                                  "data": usdtContract.methods.transfer(to, amount).encodeABI()
                              };

                              var privKey = '0x54C9FC6CF41F649863E6AFAC511E418D7A70E814814598FE5C6634326DCEC791';

                              web3.eth.accounts.signTransaction(rawTransaction, privKey, function(err,signed){

                                  if(err){
                                      $flag=false;
                                      // console.log(err);
                                      layer.msg(id+'会员审核不通过');
                                      return true;
                                  }

                                  web3.eth.sendSignedTransaction(signed.rawTransaction, function(err, result){
                                      if(!err){
                                          //传送数据
                                          $.ajax({
                                              type: 'POST',
                                              url: '{:U("doWithdrawETH")}',
                                              data: {
                                                  'txhash': result,
                                                  'id' : id
                                              },
                                              dataType: 'json',

                                              success: function(data){

                                                  if (data.code == 0) {
                                                      // alert(data.msg);
                                                      $flag=false;
                                                      // window.location ="{:U('withdrawCoin')}";
                                                      layer.msg('操作失败');
                                                      // } else {
                                                      //     alert(data.msg);
                                                      //     return;
                                                  }else{
                                                    window.location.reload();
                                                  }

                                              }
                                          });
                                      }else{
                                          layer.msg(id+'会员审核不通过');
                                          // console.log(err);
                                          $flag=false;
                                          return true;
                                      }
                                  })
                              })

                          })

                      }else{
                          // console.log(err)
                          $flag=false;
                          layer.msg(id+'会员审核不通过');
                          return true;
                      }

                  })
              }else{
                  // console.log(error);
                  $flag=false;
                  layer.msg(id+'会员审核不通过');
                  return true;
              }

          });
      }







  </script>

</block>